<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改回收垃圾')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-trash-edit" th:object="${trash}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">垃圾名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" th:field="*{name}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">垃圾类型：</label>
				<div class="col-sm-8">
					<select id="typeId" onchange="selecttype()" name="typeId" class="form-control m-b"  th:field="*{typeId}" th:with="list=${@trashType.selectTrashTypeList(null)}">
						<option th:each="trashtype : ${list}" th:text="${trashtype.name}" th:value="${trashtype.id}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">清单垃圾类型名称：</label>
				<div class="col-sm-8">
					<select id="trashDetailedId" name="trashDetailedId" class="form-control m-b" >
					</select>
					<input id="trashDetailed" name="trashDetailed" th:field="*{trashDetailedId}" class="form-control" type="hidden">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单位类型 ：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="unitType" class="form-control m-b"th:field="*{unitType}" th:with="type=${@dict.getType('sys_unit_type')}">
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="status" class="form-control m-b"th:field="*{status}" th:with="type=${@dict.getType('sys_trash_status')}">
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
					</div>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/trash";
		$("#form-trash-edit").validate({
			rules:{
				name:{
					required:true,
				},typeId:{
					required:true,
				},trashDetailedId:{
					required:true,
				},unitType:{
					required:true,
				},status:{
					required:true,
				}
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-trash-edit').serialize());
	        }
	    }
		$(document).ready(function() {
			selecttype()
		});
		function selecttype() {
			debugger
			var  typeId =$("#typeId").val();
			var  trashDetailed =$("#trashDetailed").val();
			$.ajax({
				url: "/system/trashDetailedList/listBytypeId?typeId="+typeId,
				type: "get",
				contentType: "application/json",
				timeout: 30000, //超时时间：30秒
				async: false,//false-同步（当这个ajax执行完后才会继续执行其他代码）；异步-与其他代码互不影响，一起运行。
				success: function (data) {
					$("#trashDetailedId").html("");
					if (data!=null&&data.length>0){
						for (var i = 0; i <data.length; i++) {
							var id=data[i].id;
							var typeDetailed=data[i].name;
							if (id==trashDetailed) {
								$("#trashDetailedId").append('<option selected="selected" value="'+id+'">'+typeDetailed+'</option>>')
							}else {
								$("#trashDetailedId").append('<option value="'+id+'">'+typeDetailed+'</option>>')
							}

						}
					}
				}, error: function (data) {
					console.log(data);
				}
			})
		};
	</script>
</body>
</html>
